from datetime import date, datetime
from typing import Optional
from pydantic import BaseModel, Field
from app.models.models import HonorType

# 简化的学生模型 (类似 StudentResponse 中的 area: AreaSimple)
class StudentSimple(BaseModel):
    id: int
    student_id: str = Field(..., description="学号")  # 如果需要学号
    name: str = Field(..., description="学员姓名")


    class Config:
        from_attributes = True

# 简化的课程模型
class CourseSimple(BaseModel):
    id: int
    title: str = Field(..., description="课程名称")


    class Config:
        from_attributes = True

class HonorBase(BaseModel):
    name: str = Field(..., description="荣誉名称")
    type: HonorType = Field(..., description="荣誉类型")
    image_url: Optional[str] = Field(None, description="图片URL")
    issue_date: date = Field(..., description="颁发日期")
    course_id: int = Field(..., description="课程ID")
    student_id: int = Field(..., description="学员ID")
    # student_name: Optional[int] = Field(None, description="学员姓名")
    class Config:
        from_attributes = True

class HonorCreate(HonorBase):
    pass

class HonorUpdate(BaseModel):
    name: Optional[str] = Field(None, description="荣誉名称")
    type: Optional[HonorType] = Field(None, description="荣誉类型")
    image_url: Optional[str] = Field(None, description="图片URL")
    issue_date: Optional[date] = Field(None, description="颁发日期")
    course_id: Optional[int] = Field(None, description="课程ID")
    student_id: Optional[int] = Field(None, description="学员ID")


class HonorResponse(HonorBase):
    id: int
    created_at: datetime
    updated_at: datetime
    student: StudentSimple = Field(..., description="关联学员信息")
    course: CourseSimple = Field(..., description="关联课程信息")
    class Config:
        from_attributes = True

class HonorListResponse(BaseModel):
    total: int = Field(default=0, description="总记录数")
    items: list[HonorResponse] = Field(default_factory=list, description="荣誉列表")

class HonorDetailResponse(HonorResponse):
    pass